import { Component } from 'react';

import { ScrollList, Boxs, Toast, Button, Group, TextField} from 'saltui';
const { HBox, Box } = Boxs;
import DB from '../../../app/db';
import { URLS,nodataIcon } from '../../../app/variables';
import './PageHome.less';
import SelectMember from 'components/selectMember';

const Item = (props) => <div className="t-MT2 t-P8 t-MR10" style={{'backgroundColor':'#f2f2f2'}}key={props.noticeUserId}>{props.userName}</div>;
export default class PageHome extends Component {


 constructor(props) {
    super(props);

    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    
    let id = this.props.params.id;
    let meetingId = this.props.params.meetingId;
    let orgId = document.getElementById("orgHiddenId").value;
    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    var hasBottomTab =  document.getElementById("hasBottomTab").value;
    var winHeight = getScrollHigh(1, 1, hasBottomTab);
    this.state = {
      id:id,
      meetingId:meetingId,
      orgId:orgId,
      jsonStrReceiveUser:'',
      jsonStrInviteUser:'',
      thirdMenuType:thirdMenuType,
      userId:getLoginUserInfo().userId,
      isAttendMeeting:1,
      winHeight,winHeight
    };

    
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
          title : "转本部门",//控制标题文本，空字符串表示显示默认文本
          onSuccess : function(result) {},
          onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
          title: {
              text: "转本部门",
              icon: '',
              actionmenu: {}
          },
      });
    }

    let t = this;
    let userId = document.getElementById("userHiddenId").value;
    var isHelpNew = 1;
    dd.util.domainStorage.getItem({ //帮助按钮
       name:'meeting_helpNew_'+userId , // 存储信息的key值
       onSuccess : function(info) {
          var helpNew = info.value;
          if( typeof(helpNew) == 'undefined' || helpNew == '' ){
            isHelpNew = 2;
          }
          //初始化按钮
          t.initButton(isHelpNew);
       },
       onFail : function(err) {
            //alert(JSON.stringify(err));
       }
    });
  }

  //初始化按钮
  initButton(isHelpNew){
    //设置帮助
    /*dd.biz.navigation.setIcon({
        showIcon : true,//是否显示icon
        iconIndex : isHelpNew,//显示的iconIndex,如上图
        onSuccess : function(result) {
            location.hash='help/help_index';
        },
        onFail : function(err) {
        //jsapi调用失败将会回调此函数
        }
    });*/
  }
  
  submit(){
    let t = this;
    // let jsonStrReceiveUser = this.state.jsonStrReceiveUser;
    // if (jsonStrReceiveUser=="" || jsonStrReceiveUser==null || jsonStrReceiveUser==undefined || jsonStrReceiveUser.length==0) {
    //   Toast.show({
    //     type: 'error',
    //     content: '请选择接收人',
    //     onHide: function () {
    //     }
    //   });
    //   return;
    // }else{
    //   jsonStrReceiveUser = JSON.stringify(jsonStrReceiveUser);
    // }
    let jsonStrInviteUser = this.state.jsonStrInviteUser;
    if (jsonStrInviteUser=="" || jsonStrInviteUser==null || jsonStrInviteUser==undefined || jsonStrInviteUser.length==0) {
      Toast.show({
        type: 'error',
        content: '请选择接收人',
        onHide: function () {
        }
      });
      return;
    }else{
      jsonStrInviteUser = JSON.stringify(jsonStrInviteUser);
    }
    let param = {
      id:this.state.id,
      meetingId:this.state.meetingId,
      jsonStrReceiveUser: '',
      jsonStrInviteUser: jsonStrInviteUser
    }

    DB.SomeModuleAPI.turnoverSave(param).then((content) => {
      //返回至列表页面
      setTimeout(function(){
        t.cancel();
      },1500);
      Toast.show({
        type: 'success',
        content: content,
      });
    }).catch((error) => {
      if(typeof(error.errorMsg) == 'undefined'){
        Toast.show({
          type: 'error',
          content: '提交出错'
        });
      }else{
        Toast.show({
          type: 'error',
          content: error.errorMsg
        });
      }
    });
  }

  cancel(){
    // var thirdMenuType = this.state.thirdMenuType;
    // if(thirdMenuType=="DING"){
    //   dd.biz.navigation.goBack();
    // }else if(thirdMenuType=="WX"){
    //   //wx.closeWindow();
    //   history.back();
    // }else if(thirdMenuType=="MH"){
    //   emp.navigateBack();
    // }
    history.back();
  }

  //获取联系人
  changeSelectMember(field, newValue){
      this.setState({
        [field]: newValue
      });
  }

  render() {
    let t = this;
    let listHeight = {height: t.state.winHeight};
    return (
      <div>
        <div>
          <Group.List>
            <SelectMember
              required={true}
              readOnly={false}
              label="接收人"
              placeholder="请选择接收人"
              code="user"
              checkType="checkbox"
              isDelete={true}
              showType="list"
              queryLimit="1"
              limitData={this.state.userId}
              onChange={this.changeSelectMember.bind(this,"jsonStrInviteUser")}
            />
          </Group.List>
          <Group.List> 
            <HBox>
              <Box flex='0'>
                <div className='t-field-layout-h-label t-FS15' style={{ "paddingLeft": '16px !important' }}>历史邀请人</div>
              </Box>
              <Box flex='3' hAlign='center'>
                <div style={listHeight}>
                  <ScrollList
                    url={URLS.invitedHistory}
                    pageSize={10}
                    beforeFetch={(param, form) => { param.applyRecordId = t.state.meetingId; return param; }}
                    processData={data => data}
                    noDataImage={""}
                    noDataTip={""}
                    ref={(c) => { this.invitedHistoryList = c; }}
                  >
                    <Item />
                  </ScrollList>
                </div>
              </Box>
            </HBox>
          </Group.List>
          {/* <Group.List>
              <SelectField
                required
                label="本人是否参会"
                options={[{text:'参会',value:1,checked:true},{text:'不参会',value:0}]}
                onSelect={this.typeChange.bind(this,'isAttendMeeting')}
                value={this.state.isAttendMeeting}
              />
          </Group.List>
          <Group.List>
            <SelectMember
              required={true}
              readOnly={false}
              label="带参会人"
              placeholder="请选择带参会人"
              code="user"
              checkType="radio"
              isDelete={true}
              showType="list"
              onChange={this.changeSelectMember.bind(this,"jsonStrReceiveUser")}
            />
          </Group.List> */}
        </div>
        <div >
            <Button.Group >
                <Button type="secondary" display="inline" onClick={this.cancel.bind(this)}>取消</Button>
                <Button type="primary" display="inline" onClick={this.submit.bind(this)}>确定</Button>
            </Button.Group>
        </div>
      </div>
    );
  }
}


